/*******************************************************************************
* Project: QSAR(Cute Software Architecture) 
*
* Copyright: Copyright(C) 2024 by YuetingBen, All Rights Reserved
*
* File name: CanTp.c
*
* Brief: ;
*
* Author: Yueting.Ben
*
* Module: CanTp
*
*******************************************************************************/

/** HEADER FILES **/
#include "CanTp.h"


/** MACRO DEFINITION **/
#define N_PDU_SF_TYPE        0u
#define N_PDU_FF_TYPE        1u
#define N_PDU_CF_TYPE        2u
#define N_PDU_FC_TYPE        3u


#define N_PDU_SF_MAX_DATA_LEN      7u


#define CANTP_RX_NPDU_DATA_PTR   canTpRxNSduPtr->CanTpRxNPdu.CanTpRxNPduRef->MetaDataTypeRef->MetaDataItem
#define CANTP_RX_TXFCPDU_DATA_PTR  canTpRxNSduPtr->CanTpTxFcNPdu.CanTpTxFcNPduRef->MetaDataTypeRef->MetaDataItem
#define CANTP_TX_NPDU_DATA_PTR  canTpTxNSduPtr->CanTpTxNPdu.CanTpTxNPduRef->MetaDataTypeRef->MetaDataItem
#define CANTP_TX_RXFCPDU_DATA_PTR  canTpTxNSduPtr->CanTpRxFcNPdu.CanTpTxFcNPduRef->MetaDataTypeRef->MetaDataItem

/** TYPEDEF DEFINITION **/
typedef uint8 CanTpRxTriggerType;
#define CANTP_RX_TRIGGER_SF ((CanTpRxTriggerType)0x00)
#define CANTP_RX_TRIGGER_FF ((CanTpRxTriggerType)0x01)
#define CANTP_RX_TRIGGER_CF ((CanTpRxTriggerType)0x02)
#define CANTP_RX_TRIGGER_FC ((CanTpRxTriggerType)0x03)
#define CANTP_RX_TRIGGER_NONE ((CanTpRxTriggerType)0xFF)


typedef struct
{
    uint8 nPduType : 4;
    uint8 dataLength : 4;
    uint8 data[7];
}CanTpSignalFramePduType;


typedef struct
{
    uint16 nPduType : 4;
    uint16 dataLength : 12;
    uint8 data[6];
}CanTpFirstFramePduType;


typedef struct
{
    uint8 nPduType : 4;
    uint8 sn : 4;
    uint8 data[7];
}CanTpConsecutiveFramePduType;


typedef struct
{
    uint8 nPduType : 4;
    uint8 fs : 4;
    uint8 bs;
    uint8 stmin;
}CanTpFlowControlPduType;


typedef union
{
    CanTpSignalFramePduType signalFrame;
    CanTpFirstFramePduType firstFrame;
    CanTpConsecutiveFramePduType consecutiveFrame;
    CanTpFlowControlPduType flowControlFrame;
}CanTpPduType;

typedef enum
{
    CANTP_TXSTATE_IDLE = 0x00,
    CANTP_TXSTATE_TRANSMIT_SF,
    CANTP_TXSTATE_TRANSMIT_FF,
    CANTP_TXSTATE_WAIT_FC,
    CANTP_TXSTATE_RECEIVED_FC,
    CANTP_TXSTATE_TRANSMIT_CF,
    CANTP_TXSTATE_TIMEOUT,
    CANTP_TXSTATE_FINISHED  
}CanTpTxStateType;


typedef enum
{
    CANTP_RXSTATE_IDLE = 0x00,
    CANTP_RXSTATE_RECEIVED_SF,
    CANTP_RXSTATE_RECEIVED_FF,
    CANTP_RXSTATE_TRANSMIT_FC,
    CANTP_RXSTATE_WAIT_CF,
    CANTP_RXSTATE_RECEIVED_CF,
    CANTP_RXSTATE_TIMEOUT,
    CANTP_RXSTATE_FINISHED
}CanTpRxStateType;


typedef struct
{
    CanTpTxStateType CanTpTxState; 
    uint8  TxRequestFlag;
    uint8  STmin;  /* STmin */
    uint8  BlockSize;  /* block size */
    uint8  BlockSizeCnt;  
    uint16  TxTotalLength;
    uint16  TxTransferedLength;
    PduInfoType NPduInfo;
    CanTpRxTriggerType CanTpRxTrigger;
}CanTpTxInfoType;

typedef struct
{
    CanTpRxStateType CanTpRxState;
    uint16  RxTotalLength;
    uint16  RxReceivedLength;
    PduInfoType IPduInfo;
    CanTpRxTriggerType CanTpRxTrigger;
}CanTpRxInfoType;


/** LOCAL DATA DECLARATION **/
static CanTpTxInfoType CanTpTxInfo[CanTpConf_CanTpChannel_Tx_Max];
static CanTpRxInfoType CanTpRxInfo[CanTpConf_CanTpChannel_Rx_Max];

/** GLOBAL DATA DECLARATION **/


/** LOCAL FUNCTION DECLARATION **/
static void CanTpReceivedFC(
    PduIdType TxPduId,
    const PduInfoType* PduInfoPtr
);

void CanTpTxHandle(
    CanTpTxIdType CanTpTxId
);

void CanTpRxHandle(
    CanTpRxIdType CanTpRxId
);

/** GLOBAL FUNCTION DECLARATION **/

void CanTp_Shutdown (
    void
);

Std_ReturnType CanTp_Transmit(
    PduIdType TxPduId,
    const PduInfoType* PduInfoPtr
);

Std_ReturnType CanTp_CancelTransmit(
    PduIdType TxPduId
);

Std_ReturnType CanTp_CancelReceive(
    PduIdType RxPduId
);

Std_ReturnType CanTp_ChangeParameter(
    PduIdType id,
    TPParameterType parameter,
    uint16 value
);

Std_ReturnType CanTp_ReadParameter(
    PduIdType id,
    TPParameterType parameter,
    uint16* value
);

void CanTp_RxIndication(
    PduIdType RxPduId,
    const PduInfoType* PduInfoPtr
);

void CanTp_TxConfirmation(
    PduIdType TxPduId,
    Std_ReturnType result
);

void CanTp_GetVersionInfo(
    Std_VersionInfoType* versionInfo
);

void CanTp_Init(
    const CanTp_ConfigType* CfgPtr
);

void CanTp_MainFunction (
    void
);


/** LOCAL DATA  **/
static CanTpTxInfoType CanTpTxInfo[CanTpConf_CanTpChannel_Tx_Max] = {0};
static CanTpRxInfoType CanTpRxInfo[CanTpConf_CanTpChannel_Rx_Max] = {0};


/** GLOBAL DATA **/


/** LOCAL FUNCTION **/

void CanTpTxHandle(
    CanTpTxIdType CanTpTxId
)
{
    CanTpTxInfoType* canTpTxInfoPtr = &CanTpTxInfo[CanTpTxId];
    CanTpTxNSduType* canTpTxNSduPtr = (CanTpTxNSduType*)&CanTpTxNSduConfig[CanTpTxId];
    static PduLengthType bufferSize;
    RetryInfoType retry;
    uint8 i;
    uint8 timerExpiredStatus = RESET;
    static uint8 sequenceNumber;
    
    switch(canTpTxInfoPtr->CanTpTxState)
    {
        case CANTP_TXSTATE_IDLE:
        {
            if(SET == canTpTxInfoPtr->TxRequestFlag)
            {
                canTpTxInfoPtr->TxRequestFlag = RESET;

                if(N_PDU_SF_MAX_DATA_LEN >= canTpTxInfoPtr->TxTotalLength)
                {
                    canTpTxInfoPtr->CanTpTxState = CANTP_TXSTATE_TRANSMIT_SF;
                }
                else
                {
                    canTpTxInfoPtr->CanTpTxState = CANTP_TXSTATE_TRANSMIT_FF;
                }
            }
            break;
        }
        case CANTP_TXSTATE_TRANSMIT_SF:
        {
            canTpTxInfoPtr->NPduInfo.SduDataPtr = &CANTP_TX_NPDU_DATA_PTR[1];
            canTpTxInfoPtr->NPduInfo.SduLength = canTpTxInfoPtr->TxTotalLength;
            /* Padding */
            for(i = 0u; i < 8u; i++)
            {
                canTpTxInfoPtr->NPduInfo.SduDataPtr[i] = CanTpGeneral.CanTpPaddingByte;
            }
            
            PduR_CanTpCopyTxData(CanTpTxId, &canTpTxInfoPtr->NPduInfo, &retry, &bufferSize);
            CANTP_TX_NPDU_DATA_PTR[0] = 0x00 | (canTpTxInfoPtr->NPduInfo.SduLength & 0x0F);
            
            canTpTxInfoPtr->NPduInfo.SduDataPtr = CANTP_TX_NPDU_DATA_PTR;
            CanIf_Transmit(CanTp_TxConfig[CanTpTxId].CanIfIndex, &canTpTxInfoPtr->NPduInfo);
            canTpTxInfoPtr->CanTpTxState = CANTP_TXSTATE_FINISHED;
            break;
        }
        case CANTP_TXSTATE_TRANSMIT_FF:
        {
            canTpTxInfoPtr->NPduInfo.SduDataPtr = &CANTP_TX_NPDU_DATA_PTR[2];
            canTpTxInfoPtr->NPduInfo.SduLength = 6;
            PduR_CanTpCopyTxData(CanTpTxId, &canTpTxInfoPtr->NPduInfo, &retry, &bufferSize);
            CANTP_TX_NPDU_DATA_PTR[0] = 0x10 | ((canTpTxInfoPtr->TxTotalLength>> 8) & 0x0F);
            CANTP_TX_NPDU_DATA_PTR[1] = (uint8)(canTpTxInfoPtr->TxTotalLength);
            
            canTpTxInfoPtr->NPduInfo.SduDataPtr = CANTP_TX_NPDU_DATA_PTR;
            CanIf_Transmit(CanTp_TxConfig[CanTpTxId].CanIfIndex, &canTpTxInfoPtr->NPduInfo);
            canTpTxInfoPtr->TxTransferedLength += 6;
            
            /* The FirstFrame shall be assigned the value zero (0) */
            sequenceNumber = 0x01;
            
            canTpTxInfoPtr->CanTpTxState = CANTP_TXSTATE_WAIT_FC;

            /* Start N_Bs timer couter */
            Tm_StartTimer(TmConf_TimerChannel_CanTpTimer, canTpTxNSduPtr->CanTpNbs);
            break;
        }
        case CANTP_TXSTATE_WAIT_FC:
        {
            if(CANTP_RX_TRIGGER_FC == canTpTxInfoPtr->CanTpRxTrigger)
            {
                canTpTxInfoPtr->CanTpTxState = CANTP_TXSTATE_TRANSMIT_CF;
                canTpTxInfoPtr->BlockSize = CANTP_TX_RXFCPDU_DATA_PTR[1u];
                if(0x00 == canTpTxInfoPtr->BlockSize)
                {
                    canTpTxInfoPtr->BlockSize = 0xFF;
                }
                canTpTxInfoPtr->STmin = CANTP_TX_RXFCPDU_DATA_PTR[2u] + 1u;
                canTpTxInfoPtr->BlockSizeCnt = 0u;
                Tm_StartTimer(TmConf_TimerChannel_CanTpTimer, canTpTxInfoPtr->STmin);
            }
            else
            {
                Tm_GetTimerExpiredStatus(TmConf_TimerChannel_CanTpTimer, (uint8*)&timerExpiredStatus);
                if(SET == timerExpiredStatus)
                {
                    /* N_Bs timeout */
                    canTpTxInfoPtr->CanTpTxState = CANTP_TXSTATE_TIMEOUT;
                }
            }
            canTpTxInfoPtr->CanTpRxTrigger = CANTP_RX_TRIGGER_NONE;
            break;
        }
        case CANTP_TXSTATE_RECEIVED_FC:
        {
            break;
        }
        case CANTP_TXSTATE_TRANSMIT_CF:
        {
            Tm_GetTimerExpiredStatus(TmConf_TimerChannel_CanTpTimer, (uint8*)&timerExpiredStatus);
            if(SET == timerExpiredStatus)
            {
                Tm_StartTimer(TmConf_TimerChannel_CanTpTimer, canTpTxInfoPtr->STmin);

                /* Check transmit length */
                canTpTxInfoPtr->BlockSizeCnt++;
                canTpTxInfoPtr->TxTransferedLength += 7u;
                if(canTpTxInfoPtr->TxTransferedLength >= canTpTxInfoPtr->TxTotalLength)
                {
                    canTpTxInfoPtr->CanTpTxState = CANTP_TXSTATE_FINISHED;
                    
                    canTpTxInfoPtr->NPduInfo.SduLength = 7u - (canTpTxInfoPtr->TxTransferedLength - canTpTxInfoPtr->TxTotalLength);
                }
                else
                {
                    /* ConsecutiveFrame number over BlockSize, required new FlowControl frame  */
                    if(canTpTxInfoPtr->BlockSizeCnt >= canTpTxInfoPtr->BlockSize)
                    {
                        canTpTxInfoPtr->CanTpTxState = CANTP_TXSTATE_WAIT_FC;
                        canTpTxInfoPtr->BlockSizeCnt = 0u;

                        /* Start N_Bs timer couter */
                        Tm_StartTimer(TmConf_TimerChannel_CanTpTimer, canTpTxNSduPtr->CanTpNbs);
                    }
                    /* Transmit Consecutive Frame with full data, length shall be 7 */
                    canTpTxInfoPtr->NPduInfo.SduLength = 7u;
                }

                /* Padding */
                canTpTxInfoPtr->NPduInfo.SduDataPtr = CANTP_TX_NPDU_DATA_PTR;
                for(i = 0u; i < 8u; i++)
                {
                    canTpTxInfoPtr->NPduInfo.SduDataPtr[i] = CanTpGeneral.CanTpPaddingByte;
                }
                /* Fill PCI byte information, ConsecutiveFrame + SequenceNumber(SN) */
                canTpTxInfoPtr->NPduInfo.SduDataPtr[0] = 0x20 | (sequenceNumber & 0x0F);

                /* Pointer the SDU data to get Dcm data */
                canTpTxInfoPtr->NPduInfo.SduDataPtr = &CANTP_TX_NPDU_DATA_PTR[1u];
                PduR_CanTpCopyTxData(CanTpTxId, &canTpTxInfoPtr->NPduInfo, &retry, &bufferSize);
                
                canTpTxInfoPtr->NPduInfo.SduDataPtr = CANTP_TX_NPDU_DATA_PTR;
                CanIf_Transmit(CanTp_TxConfig[CanTpTxId].CanIfIndex, &canTpTxInfoPtr->NPduInfo);
                sequenceNumber++;

            }

            break;
        }
        case CANTP_TXSTATE_TIMEOUT:
        {
            canTpTxInfoPtr->TxTransferedLength = 0u;
            canTpTxInfoPtr->TxTotalLength = 0u;
            canTpTxInfoPtr->CanTpTxState = CANTP_TXSTATE_IDLE;
            PduR_CanTpTxConfirmation(0, E_NOT_OK);
            break;
        }  
        case CANTP_TXSTATE_FINISHED:
        {
            canTpTxInfoPtr->TxTransferedLength = 0u;
            canTpTxInfoPtr->TxTotalLength = 0u;
            canTpTxInfoPtr->CanTpTxState = CANTP_TXSTATE_IDLE;
            PduR_CanTpTxConfirmation(0, E_OK);
            break;
        }  
    }
}


void CanTpRxHandle(
    CanTpRxIdType CanTpRxId
)
{
    CanTpRxInfoType* canTpRxInfoPtr = &CanTpRxInfo[CanTpRxId];
    CanTpTxInfoType* canTpTxInfoPtr = &CanTpTxInfo[0u];
    
    CanTpRxNSduType* canTpRxNSduPtr = (CanTpRxNSduType*)&CanTpRxNSduConfig[CanTpRxId];
    PduLengthType bufferSize;
    uint8 i;
    uint8 timerExpiredStatus = RESET;

    switch(canTpRxInfoPtr->CanTpRxState)
    {
        case CANTP_RXSTATE_IDLE:
        {
            canTpRxInfoPtr->RxReceivedLength = 0u;
            canTpRxInfoPtr->RxTotalLength = 0u;

            if(CANTP_RX_TRIGGER_SF == canTpRxInfoPtr->CanTpRxTrigger)
            {
                canTpRxInfoPtr->RxTotalLength= (PduLengthType)(CANTP_RX_NPDU_DATA_PTR[0] & 0x0F);

                canTpRxInfoPtr->IPduInfo.SduDataPtr = &CANTP_RX_NPDU_DATA_PTR[1];
                canTpRxInfoPtr->IPduInfo.SduLength = 7u;
                PduR_CanTpStartOfReception(CanTpRxId, &canTpRxInfoPtr->IPduInfo, canTpRxInfoPtr->RxTotalLength, &bufferSize);
                PduR_CanTpCopyRxData(CanTpRxId, &canTpRxInfoPtr->IPduInfo, &bufferSize);
                canTpRxInfoPtr->CanTpRxState = CANTP_RXSTATE_FINISHED;
            }
            else if(CANTP_RX_TRIGGER_FF == canTpRxInfoPtr->CanTpRxTrigger)
            {
                if(CANTP_PHYSICAL == canTpRxNSduPtr->CanTpRxTaType)
                {
                    canTpRxInfoPtr->RxTotalLength = (PduLengthType)((CANTP_RX_NPDU_DATA_PTR[0] & 0x0F) << 8 | CANTP_RX_NPDU_DATA_PTR[1]);

                    canTpRxInfoPtr->IPduInfo.SduDataPtr = &CANTP_RX_NPDU_DATA_PTR[2];
                    canTpRxInfoPtr->IPduInfo.SduLength = 6u;
                    PduR_CanTpStartOfReception(CanTpRxId, &canTpRxInfoPtr->IPduInfo, canTpRxInfoPtr->RxTotalLength, &bufferSize);
                    PduR_CanTpCopyRxData(CanTpRxId, &canTpRxInfoPtr->IPduInfo, &bufferSize);
                    canTpRxInfoPtr->RxReceivedLength += canTpRxInfoPtr->IPduInfo.SduLength;

                    canTpRxInfoPtr->CanTpRxState = CANTP_RXSTATE_TRANSMIT_FC; 
                }
            }
            else
            {
                /* Do nothing */
            }
            canTpRxInfoPtr->CanTpRxTrigger = CANTP_RX_TRIGGER_NONE;
            break;
        }
        case CANTP_RXSTATE_TRANSMIT_FC:
        {
            canTpTxInfoPtr->NPduInfo.SduDataPtr = CANTP_RX_TXFCPDU_DATA_PTR;
            /* Padding */
            for(i = 0u; i < 8u; i++)
            {
                canTpTxInfoPtr->NPduInfo.SduDataPtr[i] = CanTpGeneral.CanTpPaddingByte;
            }
            canTpTxInfoPtr->NPduInfo.SduDataPtr[0] = 0x30;
            canTpTxInfoPtr->NPduInfo.SduDataPtr[1] = canTpRxNSduPtr->CanTpBs;
            canTpTxInfoPtr->NPduInfo.SduDataPtr[2] = canTpRxNSduPtr->CanTpSTmin;
            canTpTxInfoPtr->NPduInfo.SduLength = 8u;
            CanIf_Transmit(CanTp_TxConfig[0u].CanIfIndex, &canTpTxInfoPtr->NPduInfo);
            
            canTpRxInfoPtr->CanTpRxState = CANTP_RXSTATE_WAIT_CF;

            /* Start N_Cr timer couter */
            Tm_StartTimer(TmConf_TimerChannel_CanTpTimer, canTpRxNSduPtr->CanTpNcr);

            break;
        }
        case CANTP_RXSTATE_WAIT_CF:
        {
            if(CANTP_RX_TRIGGER_CF == canTpRxInfoPtr->CanTpRxTrigger)
            {
                canTpRxInfoPtr->IPduInfo.SduDataPtr = &CANTP_RX_NPDU_DATA_PTR[1u];
                canTpRxInfoPtr->IPduInfo.SduLength = 7u;

                PduR_CanTpCopyRxData(CanTpRxId, &canTpRxInfoPtr->IPduInfo, &bufferSize);
                canTpRxInfoPtr->RxReceivedLength += canTpRxInfoPtr->IPduInfo.SduLength;

                if(canTpRxInfoPtr->RxReceivedLength >= canTpRxInfoPtr->RxTotalLength)
                {
                    canTpRxInfoPtr->CanTpRxState = CANTP_RXSTATE_FINISHED;
                }
                else
                {
                    /* Start N_Cr timer couter */
                    Tm_StartTimer(TmConf_TimerChannel_CanTpTimer, canTpRxNSduPtr->CanTpNcr);
                }
            }
            else
            {
                Tm_GetTimerExpiredStatus(TmConf_TimerChannel_CanTpTimer, (uint8*)&timerExpiredStatus);
                if(SET == timerExpiredStatus)
                {
                    canTpRxInfoPtr->CanTpRxState = CANTP_RXSTATE_TIMEOUT;
                }  
            }

            canTpRxInfoPtr->CanTpRxTrigger = CANTP_RX_TRIGGER_NONE;
            break;
        }
        case CANTP_RXSTATE_TIMEOUT:
        {
            PduR_CanTpRxIndication(CanTpRxId, E_NOT_OK);
            canTpRxInfoPtr->RxReceivedLength = 0u;
            canTpRxInfoPtr->RxTotalLength = 0u;
            canTpRxInfoPtr->CanTpRxState = CANTP_RXSTATE_IDLE;
            break;
        }
        case CANTP_RXSTATE_FINISHED:
        {
            PduR_CanTpRxIndication(CanTpRxId, E_OK);
            canTpRxInfoPtr->RxReceivedLength = 0u;
            canTpRxInfoPtr->RxTotalLength = 0u;
            canTpRxInfoPtr->CanTpRxState = CANTP_RXSTATE_IDLE;
            break;
        }
    }
}


/** GLOBAL FUNCTION **/

/*******************************************************************************
* -Name         CanTp_Shutdown
* -Brief        This function is called to shutdown the CanTp module
* -Details      None
* -Param[in]    None
* -Return       None          
*******************************************************************************/
void CanTp_Shutdown (
    void
)
{
    
}

/*******************************************************************************
* -Name         CanTp_Transmit
* -Brief        Requests transmission of a PDU
* -Details      None
* -Param[in]    TxPduId: Identifier of the PDU to be transmitted
* -Param[in]    PduInfoPtr: Length of and pointer to the PDU data and pointer to MetaData
* -Return       E_OK: Transmit request has been accepted
                E_NOT_OK: Transmit request has not been accepted
*******************************************************************************/
Std_ReturnType CanTp_Transmit(
    PduIdType TxPduId,
    const PduInfoType* PduInfoPtr
)
{
    CanTpTxInfoType* canTpTxInfoPtr = &CanTpTxInfo[TxPduId];
    
    canTpTxInfoPtr->TxRequestFlag = SET; 
    canTpTxInfoPtr->TxTotalLength = PduInfoPtr->SduLength;
    canTpTxInfoPtr->TxTransferedLength = 0u;
    
}

/*******************************************************************************
* -Name         CanTp_CancelTransmit
* -Brief        Requests cancellation of an ongoing transmission of a PDU in a lower layer communication module
* -Details      None
* -Param[in]    TxPduId: Identifier of the PDU to be transmitted
* -Return       E_OK: Cancellation was executed successfully by the destination module
                E_NOT_OK: Cancellation was rejected by the destination module
*******************************************************************************/
Std_ReturnType CanTp_CancelTransmit(
    PduIdType TxPduId
)
{
    
}

/*******************************************************************************
* -Name         CanTp_CancelReceive
* -Brief        Requests cancellation of an ongoing reception of a PDU in a lower layer transport protocol module
* -Details      None
* -Param[in]    RxPduId: Identification of the PDU to be cancelled
* -Return       E_OK: Cancellation was executed successfully by the destination module
                E_NOT_OK: Cancellation was rejected by the destination module
*******************************************************************************/
Std_ReturnType CanTp_CancelReceive(
    PduIdType RxPduId
)
{
    
}

/*******************************************************************************
* -Name         CanTp_ChangeParameter
* -Brief        Request to change a specific transport protocol parameter (e.g. block size)
* -Details      None
* -Param[in]    id: Identification of the PDU which the parameter change shall affect
* -Param[in]    parameter: ID of the parameter that shall be changed
* -Param[in]    value: The new value of the parameter
* -Return       E_OK: The parameter was changed successfully
                E_NOT_OK: The parameter change was rejected
*******************************************************************************/
Std_ReturnType CanTp_ChangeParameter(
    PduIdType id,
    TPParameterType parameter,
    uint16 value
)
{
    
}

/*******************************************************************************
* -Name         CanTp_ReadParameter
* -Brief        This service is used to read the current value of reception parameters BS and STmin for a specified N-SDU
* -Details      None
* -Param[in]    id: Identifier of the received N-SDU on which the reception parameter are read
* -Param[in]    parameter: Specify the parameter to which the value has to be read (BS or STmin).
* -Param[out]   value: Pointer where the parameter value will be provided
* -Return       E_OK: request is accepted
                E_NOT_OK: request is not accepted
*******************************************************************************/
Std_ReturnType CanTp_ReadParameter(
    PduIdType id,
    TPParameterType parameter,
    uint16* value
)
{
    
}


/*******************************************************************************
* -Name         CanTp_RxIndication
* -Brief        Indication of a received PDU from a lower layer communication interface module
* -Details      None
* -Param[in]    RxPduId: ID of the received PDU
* -Param[in]    PduInfoPtr: Contains the length (SduLength) of the received PDU, a pointer
                            to a buffer (SduDataPtr) containing the PDU, and the MetaData
                            related to this PDU
* -Return       None
*******************************************************************************/
void CanTp_RxIndication(
    PduIdType RxPduId,
    const PduInfoType* PduInfoPtr
)
{
    CanTpRxInfoType* canTpRxInfoPtr = &CanTpRxInfo[RxPduId];
    CanTpTxInfoType* canTpTxInfoPtr = &CanTpTxInfo[0u];
    CanTpRxNSduType* canTpRxNSduPtr = (CanTpRxNSduType*)&CanTpRxNSduConfig[RxPduId];
    uint8 nPduType;
    
    nPduType = CANTP_RX_NPDU_DATA_PTR[0] >> 4u;
    canTpRxInfoPtr->CanTpRxTrigger = nPduType;
    canTpTxInfoPtr->CanTpRxTrigger = nPduType;
}


/*******************************************************************************
* -Name         CanTp_TxConfirmation
* -Brief        The lower layer communication interface module confirms the transmission of a PDU, or the failure to transmit a PDU. 
* -Details      None
* -Param[in]    TxPduId: ID of the PDU that has been transmitted
* -Param[in]    result: E_OK: The PDU was transmitted. E_NOT_OK: Transmission of the PDU failed
* -Return       None          
*******************************************************************************/
void CanTp_TxConfirmation(
    PduIdType TxPduId,
    Std_ReturnType result
)
{

}



/*******************************************************************************
* -Name         CanTp_GetVersionInfo
* -Brief        Returns the version information of this module 
* -Details      None
* -Param[out]   versioninfo: Pointer to the version information of this module
* -Return       None          
*******************************************************************************/
void CanTp_GetVersionInfo(
    Std_VersionInfoType* versionInfo
)
{
    versionInfo->vendorID = (uint16)YSAR_VENDOR_ID;
    versionInfo->moduleID = (uint8)CANTP_MODULE_ID;
    versionInfo->sw_major_version = (uint8)CANTP_SW_MAJOR_VERSION;
    versionInfo->sw_minor_version = (uint8)CANTP_SW_MINOR_VERSION;
    versionInfo->sw_patch_version = (uint8)CANTP_SW_PATCH_VERSION;
}

/*******************************************************************************
* -Name         CanTp_Init
* -Brief        This function initializes the CanTp module
* -Details      None
* -Param[in]    CfgPtr: Pointer to the CanTp post-build configuration data
* -Return       None          
*******************************************************************************/
void CanTp_Init(
    const CanTp_ConfigType* CfgPtr
)
{
    CanTpRxInfoType* canTpRxInfoPtr;
    CanTpTxInfoType* canTpTxInfoPtr;
    
    CanTpTxIdType canTpTxId;
    CanTpRxIdType canTpRxId;

    for(canTpTxId = 0u; canTpTxId < CanTpConf_CanTpChannel_Tx_Max; canTpTxId++)
    {
        canTpTxInfoPtr = &CanTpTxInfo[canTpTxId];
        canTpTxInfoPtr->CanTpRxTrigger = CANTP_RX_TRIGGER_NONE;
    }
    
    for(canTpRxId = 0u; canTpRxId < CanTpConf_CanTpChannel_Rx_Max; canTpRxId++)
    {
        canTpRxInfoPtr = &CanTpRxInfo[canTpRxId];
        canTpRxInfoPtr->CanTpRxTrigger = CANTP_RX_TRIGGER_NONE;
    }

}

/*******************************************************************************
* -Name         CanTp_MainFunction
* -Brief        The main function for scheduling the CAN TP
* -Details      None
* -Param[in]    None
* -Return       None          
*******************************************************************************/
void CanTp_MainFunction(
    void
)
{
    CanTpRxInfoType* canTpRxInfoPtr = &CanTpRxInfo[0u];

    CanTpTxIdType canTpTxId;
    CanTpRxIdType canTpRxId;

    for(canTpTxId = 0u; canTpTxId < CanTpConf_CanTpChannel_Tx_Max; canTpTxId++)
    {
        CanTpTxHandle(canTpTxId);
    }
    
    for(canTpRxId = 0u; canTpRxId < CanTpConf_CanTpChannel_Rx_Max; canTpRxId++)
    {
        CanTpRxHandle(canTpRxId);
    }
}

